import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Main from '../components/Main.vue'
import Welcome from '../components/Welcome.vue'
import Modify from '../components/Modify.vue'
import Application from '../components/Application.vue'
import Talk from '../components/Talk.vue'
import Moral from '../Application/Moral.vue'
import Sport from '../Application/Sport.vue'
import Art from '../Application/Art.vue'
import Labor from '../Application/Labor.vue'
import Creation from '../Application/Creation.vue'
Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const router = new VueRouter({
  routes:[
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',//当用户访问path为/Login时
      name: 'login',
      component: Login//展示上方的Login组件
    },
    {
      path: '/Main',
      component: Main,
      redirect:'/welcome',
      children:[{
        path:'/welcome',
        component:Welcome},
        {path:'/Modify',
        component:Modify},
        {path:'/Talk',
        component:Talk},
        {path:'/Application',
      component:Application,
      children:[{path:'/Moral',component:Moral},{path:'/Sport',component:Sport},{path:'/Art',component:Art},{path:'/Labor',component:Labor},{path:'/Creation',component:Creation}]
    },
      ]
    }
  ]
  
})

//挂载路由导航守卫
//router.beforeEach((to,from,next)=>{
//to将要访问的路径
//from代表从哪个路径跳转过来
//next是一个函数，表示放行(next('/login')强制跳转)
//if(to.path='/login')return next()
//获取token，这里前端要存的是cookie，需要再学习一下完善
//const tokenStr = window.sesssionStorage.getItem('token')

//if(!tokenStr)return next('/login')
//next()
//})

export default router
